package cn.gzsxt.music.service.impl;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.gzsxt.music.mapper.LableMapper;
import cn.gzsxt.music.service.LableService;

@Service
public class LableServiceImpl implements LableService {
	
	@Autowired
	private LableMapper mapper;

	@Override
	public List<Map<String, Object>> getAllLables() {
		return mapper.getAllLables();
	}

	@Override
	public String toLables(String song_label) {
		//System.out.println(song_label);
		StringBuffer sb = new StringBuffer();
		List<Map<String,Object>> labelsMapper = mapper.getAllLables();
		Map<String,String> labels = new HashMap<String,String>();
		for (Map<String,Object> label : labelsMapper) {
			labels.put(Integer.toString((int)label.get("label_id")), (String)label.get("label_name"));
		}
		String [] params = song_label.split(",");
		for (int i = 0; i < params.length; i++) {
			sb.append(labels.get(params[i].trim())+",");
		}
		sb.deleteCharAt(sb.length()-1);
		//System.out.println(sb);
		return sb.toString();
	}
	
}
